package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PublicOpinionReport;
import com.ruoyi.system.service.IPublicOpinionReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 简报模板Controller
 * 
 * @author hwcazy
 * @date 2021-07-08
 */
@RestController
@RequestMapping("/system/report")
public class PublicOpinionReportController extends BaseController
{
    @Autowired
    private IPublicOpinionReportService publicOpinionReportService;

    /**
     * 查询简报模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(PublicOpinionReport publicOpinionReport)
    {
        publicOpinionReport.setTenantCode(SecurityUtils.getLoginUser().getUser().getTenantCode());
        startPage();
        List<PublicOpinionReport> list = publicOpinionReportService.selectPublicOpinionReportList(publicOpinionReport);
        return getDataTable(list);
    }

    /**
     * 导出简报模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "简报模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PublicOpinionReport publicOpinionReport)
    {
        publicOpinionReport.setTenantCode(SecurityUtils.getLoginUser().getUser().getTenantCode());
        List<PublicOpinionReport> list = publicOpinionReportService.selectPublicOpinionReportList(publicOpinionReport);
        ExcelUtil<PublicOpinionReport> util = new ExcelUtil<PublicOpinionReport>(PublicOpinionReport.class);
        return util.exportExcel(list, "简报模板数据");
    }

    /**
     * 获取简报模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(publicOpinionReportService.selectPublicOpinionReportById(id));
    }

    /**
     * 新增简报模板
     */
    @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "简报模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PublicOpinionReport publicOpinionReport)
    {
        publicOpinionReport.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        publicOpinionReport.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
        publicOpinionReport.setTenantCode(SecurityUtils.getLoginUser().getUser().getTenantCode());
        return toAjax(publicOpinionReportService.insertPublicOpinionReport(publicOpinionReport));
    }

    /**
     * 修改简报模板
     */
    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "简报模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PublicOpinionReport publicOpinionReport)
    {
        return toAjax(publicOpinionReportService.updatePublicOpinionReport(publicOpinionReport));
    }

    /**
     * 删除简报模板
     */
    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "简报模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(publicOpinionReportService.deletePublicOpinionReportByIds(ids));
    }
}
